package com.teamcenter.rac.massupdate.utils;

import java.util.Arrays;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;

import com.teamcenter.rac.viewer.listener.ColumnSelectionListener;
import com.teamcenter.rac.viewer.view.ViewerHelper;

public class MassUpdateTableHelper
{
  public static TableViewer createTable(Composite paramComposite, int paramInt, boolean paramBoolean1, boolean paramBoolean2, Object paramObject, String[] paramArrayOfString1, String[] paramArrayOfString2, int[] paramArrayOfInt, ViewerComparator paramViewerComparator, boolean paramBoolean3)
  {
    TableViewer localTableViewer = new TableViewer(paramComposite, paramInt);
    if (paramViewerComparator != null) {
      localTableViewer.setComparator(new MassUpdatePropertyColumnViewerSorter());
    }
    Table localTable = localTableViewer.getTable();
    localTable.setLinesVisible(paramBoolean1);
    localTable.setHeaderVisible(paramBoolean2);
    localTable.setLayoutData(paramObject);
    ViewerHelper.addViewerColumns(localTableViewer, paramArrayOfString1, paramArrayOfString2, null, false);
    int i = localTable.getColumnCount();
    for (int j = 0; j < i; j++)
    {
      TableColumn localTableColumn = localTable.getColumn(j);
      localTableColumn.setMoveable(true);
      localTableColumn.setResizable(true);
      localTableColumn.setWidth(paramArrayOfInt[j]);
      if (paramBoolean3)
      {
        ColumnSelectionListener localColumnSelectionListener = new ColumnSelectionListener(localTableViewer);
        localTableColumn.addSelectionListener(localColumnSelectionListener);
      }
    }
    return localTableViewer;
  }
  
  public static int getIndexByValue(String[] paramArrayOfString, String paramString)
  {
    return Arrays.asList(paramArrayOfString).indexOf(paramString);
  }
  
  public static TableViewerColumn[] getTableViewerColumns(TableViewer paramTableViewer)
  {
    TableColumn[] arrayOfTableColumn = paramTableViewer.getTable().getColumns();
    TableViewerColumn[] arrayOfTableViewerColumn = new TableViewerColumn[arrayOfTableColumn.length];
    for (int i = 0; i < arrayOfTableColumn.length; i++)
    {
      TableColumn localTableColumn = arrayOfTableColumn[i];
      arrayOfTableViewerColumn[i] = ((TableViewerColumn)localTableColumn.getData("org.eclipse.jface.columnViewer"));
    }
    return arrayOfTableViewerColumn;
  }
}

